home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: Dec 3 1998
- // Author: cdt
- //
- // Procedure Name:
- // referenceEditorPanel
- //
- // Description:
- // Creates a panel that contains a reference editor.
- //
- // Input Arguments:
- // None
- //
- // Return Value:
- // None.
- //
-
- global string $_selectedFile[];
- global string $_selectedRef[];
-
- global proc referenceEdFileSelected(string $whichPanel)
- {
- global string $_selectedFile[];
- global string $_selectedRef[];
- string $activeFile;
-
- $_selectedFile = `sceneEditor -q -si
- ($whichPanel + "referenceEditorPanel")`;
- $_selectedRef = `sceneEditor -q -sr
- ($whichPanel + "referenceEditorPanel")`;
-
- if (size($_selectedFile) == 1
- && size($_selectedFile[0]) > 0
- && `file -q -ex $_selectedFile[0]`) {
-
- $activeFile = `file -q -a $_selectedFile[0]`;
-
- text -e -l $_selectedFile[0] fileNameValue;
- string $fileType[] = `file -q -type $_selectedFile[0]`;
- if (size($fileType) > 0) {
- text -e -l $fileType[0] fileTypeValue;
- } else {
- text -e -l "Unknown" fileTypeValue;
- }
-
- string $subType = `file -q -st $_selectedFile[0]`;
- text -e -l $subType fileSubTypeValue;
-
- int $writable = `file -q -w $_selectedFile[0]`;
- if ($writable) {
- text -e -l "Writable" fileIOValue;
- } else {
- text -e -l "Read Only" fileIOValue;
- }
- int $modified = `file -q -mf $_selectedFile[0]`;
- if ($modified) {
- text -e -l "Modified" fileStatusValue;
- } else {
- text -e -l "Not Modified" fileStatusValue;
- }
-
- int $deferred = `file -q -dr $_selectedFile[0]`;
- if ($deferred) {
- text -e -l "Unloaded" fileLoadValue;
- } else {
- text -e -l "Loaded" fileLoadValue;
- }
-
- string $renamePrefix = `file -q -rpr $_selectedFile[0]`;
- text -e -l $renamePrefix fileRenamePrefixValue;
- } else {
- // Nothing selected.
- //
- string $notAvailable = "N/A";
- text -e -l $notAvailable fileTypeValue;
- text -e -l $notAvailable fileSubTypeValue;
- text -e -l $notAvailable fileIOValue;
- text -e -l $notAvailable fileStatusValue;
- text -e -l $notAvailable fileLoadValue;
- text -e -l $notAvailable fileNameValue;
- text -e -l $notAvailable fileRenamePrefixValue;
- }
- }
-
- // MENU CREATION PROCEDURES
- //
-
- global proc buildReferenceFileMenu(string $parentMenu)
- //
- // Description:
- // Builds the submenu for file functionality in the reference editor.
- //
- {
- setParent -menu $parentMenu;
-
- if (`menu -query -numberOfItems $parentMenu` == 0) {
- menuItem
- -label "Create Reference"
- -command ("CreateReference")
- referenceEdCreateItem;
- menuItem -optionBox true
- -l "Create Reference Option Box"
- -c "fileOptions \"Reference\" \"projectViewer Reference\""
- referenceEdFileOptions;
-
- menuItem
- -label "Import Objects from Reference"
- -command referenceEdImportCB
- referenceEdImportItem;
-
- menuItem
- -label "Export Selection as a Reference"
- -command "referenceEdExportCB"
- referenceEdExportItem;
-
- menuItem -divider true;
-
- menuItem
- -label "Clean Up Reference"
- -command "referenceEdCleanUpCB"
- referenceEdCleanUpItem;
- }
-
- updateReferenceFileMenu($parentMenu);
- }
-
- global proc updateReferenceFileMenu(string $parentMenu)
- //
- // Description:
- // Updates the file menu in the reference editor.
- //
- {
- global string $_selectedRef[];
-
- string $oldParent = `setParent -q -menu`;
- setParent -menu $parentMenu;
-
- // Disable the export item if the selection list is empty.
- //
- int $exportEnable = (size(`ls -sl`) > 0) ? true : false;
- menuItem -edit -enable $exportEnable referenceEdExportItem;
-
- // Disable the clean reference item if there is no reference node.
- //
- int $cleanEnable = 1;
- if (size($_selectedRef) == 0 || size($_selectedRef[0]) == 0) {
- $cleanEnable = 0;
- }
- menuItem -edit -enable $cleanEnable referenceEdCleanUpItem;
-
- setParent -menu $oldParent;
- }
-
- global proc buildReferenceEditMenu(string $parentMenu)
- //
- // Description:
- // Builds the Edit submenu for the reference editor.
- //
- {
- setParent -menu $parentMenu;
-
- if (`menu -query -numberOfItems $parentMenu` == 0) {
- menuItem
- -label "Remove Reference"
- -command "referenceEdRemoveCB"
- referenceEdRemoveItem;
-
- menuItem
- -label "Select File Contents"
- -command "referenceEdSelectCB"
- referenceEdSelectItem;
- }
-
- updateReferenceEditMenu($parentMenu);
- }
-
- global proc updateReferenceEditMenu(string $parentMenu)
- //
- // Description:
- // Updates the edit menu for the reference editor.
- //
- {
- global string $_selectedFile[];
- global string $_selectedRef[];
-
- string $oldParent = `setParent -q -menu`;
- setParent -menu $parentMenu;
-
- int $enable = (size($_selectedFile) > 0) ? true : false;
- menuItem -edit -enable $enable referenceEdSelectItem;
-
- setParent -menu $oldParent;
- }
-
- global proc buildReferenceReferenceMenu(string $parentMenu)
- //
- // Desciption:
- //
- //
- {
- setParent -menu $parentMenu;
-
- if (`menu -query -numberOfItems $parentMenu` == 0) {
- menuItem
- -label "Load Reference"
- -command referenceEdLoadCB
- referenceEdLoadItem;
-
- menuItem
- -label "Unload Reference"
- -command referenceEdUnloadCB
- referenceEdUnloadItem;
-
- menuItem -divider true;
-
- menuItem
- -label "Replace Reference"
- -command referenceEdReplaceCB
- referenceEdReplaceItem;
-
- menuItem
- -subMenu true
- -label "Recent Files"
- -postMenuCommand ("buildReferenceEdRecentMenu " + $parentMenu)
- referenceEdRecentFilesItem;
- }
-
- updateReferenceReferenceMenu($parentMenu);
- }
-
- global proc updateReferenceReferenceMenu(string $parentMenu)
- //
- // Description:
- // Updates the reference menu for the reference editor.
- //
- {
- global string $_selectedRef[];
-
- string $oldParent = `setParent -q -menu`;
- setParent -menu $parentMenu;
-
- setParent -menu $oldParent;
- }
-
- // END OF MENU CREATION PROCEDURES
- //
-
- global proc referenceEditorPanel(string $panelName) {
-
- global string $gMainPane;
-
- if (!`scriptedPanelType -exists referenceEditorPanel`) {
- scriptedPanelType
- -createCallback "createRefEdPanel"
- -addCallback "addRefEdPanel"
- -removeCallback "removeRefEdPanel"
- referenceEditorPanel;
-
- setParent $gMainPane;
- scriptedPanel -unParent -type "referenceEditorPanel" $panelName;
- }
- }
-
- global proc createRefEdPanel(string $whichPanel) {
- sceneEditor
- -unParent
- -selectCommand ("referenceEdFileSelected \"" + $whichPanel + "\"")
- ($whichPanel + "referenceEditorPanel");
- }
-
- global proc buildReferenceContextHelpItems(string $nameRoot, string $menuParent)
- //
- // Description:
- // Build context sensitive menu items for the hyper shader.
- //
- // Input Arguments:
- // $nameRoot - name to use as the root of all item names
- // $menuParent - the name of the parent of this menu
- //
- // Return Value:
- // None
- //
- {
- menuItem -label "Help on Reference Editor..."
- -enableCommandRepeat false
- -command "showHelp ReferenceEditor";
- }
-
- global proc addRefEdPanel( string $whichPanel ) {
- global int $gStandardIdent;
- int $numDivisions = 100;
-
- string $rp = ($whichPanel + "referenceEditorPanel");
-
- // Add the menu.
- //
- string $fileMenu = `menu -label "File"
- -allowOptionBoxes true
- -tearOff true`;
- menu -edit
- -postMenuCommand ("updateReferenceFileMenu " + $fileMenu)
- $fileMenu;
- buildReferenceFileMenu($fileMenu);
- setParent -menu ..;
-
- string $editMenu = `menu -label "Edit"
- -allowOptionBoxes true
- -tearOff true`;
- menu -edit
- -postMenuCommand ("updateReferenceEditMenu " + $editMenu)
- $editMenu;
- buildReferenceEditMenu($editMenu);
- setParent -menu ..;
-
- string $referenceMenu = `menu -label "Reference"
- -allowOptionBoxes true
- -tearOff true`;
-
- menu -edit
- -postMenuCommand ("buildReferenceReferenceMenu " + $referenceMenu)
- $referenceMenu;
- setParent -menu ..;
-
- // Add support for the Context Sensitive Help Menu.
- //
- addContextHelpProc $whichPanel "buildReferenceContextHelpItems";
-
- string $edParent = `formLayout`;
- string $outlinerLayout = `formLayout`;
- sceneEditor -e
- -parent $outlinerLayout $rp;
-
- setParent ..;
-
- formLayout -e
- -af $rp top 0
- -af $rp left 0
- -af $rp right 0
- -af $rp bottom 0
- $outlinerLayout;
-
- frameLayout
- -l "File Particulars"
- -cll true
- -cl `optionVar -q refEdFilePartCl`
- -cc "optionVar -iv refEdFilePartCl 1"
- -ec "optionVar -iv refEdFilePartCl 0"
- -labelIndent $gStandardIdent
- fileInfoFrame;
-
- string $fInfoForm = `formLayout -nd $numDivisions fileInfoForm`;
- text -l "Name:" fileNameLabel;
- text fileNameValue;
- text -l "Type:" fileTypeLabel;
- text fileTypeValue;
- text -l "Sub-Type:" fileSubTypeLabel;
- text fileSubTypeValue;
- text -l "Status:" fileStatusLabel;
- text fileStatusValue;
- text -l "Load:" fileLoadLabel;
- text fileLoadValue;
- text -l "I/O:" fileIOLabel;
- text fileIOValue;
- text -l "Rename Prefix:" fileRenamePrefixLabel;
- text fileRenamePrefixValue;
-
- formLayout -e
- -af fileNameLabel left 0 -af fileNameLabel top 0
- -ap fileNameValue left 0 15 -af fileNameValue top 0
- -af fileTypeLabel left 0 -ac fileTypeLabel top 0 fileNameLabel
- -ap fileTypeValue left 0 15 -ac fileTypeValue top 0 fileNameLabel
- -ap fileSubTypeLabel left 0 50
- -ac fileSubTypeLabel top 0 fileNameLabel
- -ap fileSubTypeValue left 0 70
- -ac fileSubTypeValue top 0 fileNameLabel
- -af fileStatusLabel left 0
- -ac fileStatusLabel top 0 fileSubTypeLabel
- -ap fileStatusValue left 0 15
- -ac fileStatusValue top 0 fileSubTypeLabel
- -ap fileIOLabel left 0 50 -ac fileIOLabel top 0 fileSubTypeLabel
- -ap fileIOValue left 0 70 -ac fileIOValue top 0 fileSubTypeLabel
- -af fileLoadLabel left 0
- -ac fileLoadLabel top 0 fileIOLabel
- -ap fileLoadValue left 0 15
- -ac fileLoadValue top 0 fileIOLabel
- -ap fileRenamePrefixLabel left 0 50
- -ac fileRenamePrefixLabel top 0 fileIOLabel
- -ap fileRenamePrefixValue left 0 70
- -ac fileRenamePrefixValue top 0 fileIOLabel
- $fInfoForm;
-
- formLayout -e
- -af fileInfoFrame top 0
- -af fileInfoFrame left 0
- -af fileInfoFrame right 0
- -ac $outlinerLayout top 5 fileInfoFrame
- -af $outlinerLayout left 0
- -af $outlinerLayout right 0
- -af $outlinerLayout bottom 0
- $edParent;
-
- setParent $edParent;
-
- source ReferenceEdMenu;
- ReferenceEdMenu($whichPanel);
-
- referenceEdFileSelected($whichPanel);
- }
-
- global proc removeRefEdPanel(string $whichPanel)
- {
- sceneEditor -e -unParent
- ($whichPanel + "referenceEditorPanel");
- }
-
- // Global procs used by the menus...
- //
-
- global proc referenceEdImportCB()
- //
- // Description:
- // Import the contents of a reference file into the scene. The imported
- // file is no longer referenced.
- //
- {
- global string $_selectedFile[];
- if (size($_selectedFile) == 1 && size($_selectedFile[0]) > 0) {
- file -ir $_selectedFile[0];
- }
- }
-
- global proc referenceEdCleanUpCB()
- //
- // Description:
- // Cleans up the currently selected reference. Any unresolved information
- // is removed. This is a potentially dangerous option.
- //
- {
- global string $_selectedRef[];
-
- // If a reference node is not selected, then there is nothing to
- // clean up.
- //
- if (size($_selectedRef) == 0 || size($_selectedRef[0]) == 0) {
- return;
- }
-
- string $result = `confirmDialog -t "Clean Reference"
- -m ("Cleaning up the reference node, "
- +$_selectedRef[0]+", is Not Undoable.")
- -b "Clean" -b "Cancel" -db "Cancel"`;
- if ($result == "Clean") {
- file -cr $_selectedRef[0];
- }
- }
-
- global proc int referenceEdExportAsReference(string $theFile, string $fileType)
- //
- // Description:
- // This code is used to create a reference file from a
- // selection in the current scene.
- //
- // Note:
- // There are currently no options associated with this action so
- // we must use the currently set Export Selected options. Note that
- // we cannot ignore history during this operation. This case is
- // handled in the export code.
- //
- {
- int $fileExists = `file -q -ex $theFile`;
-
- int $win32 = `about -nt`;
- if ($fileExists && !$win32) {
- string $result = `confirmDialog -m "File Exists. Overwrite?"
- -b "Yes" -b "Cancel" -db "Cancel" -parent projectViewerWindow`;
- if ($result == "Cancel") {
- return false;
- }
- }
-
- if (`about -evalVersion`) {
- $fileType = "mayaPLE";
- } else if ($fileType == "") {
- $fileType = "mayaBinary";
- }
-
- string $fileOptions;
- string $translatorOptions = ($fileType+"Options");
- if (`optionVar -exists $translatorOptions`) {
- // Post the new options.
- $fileOptions = `optionVar -q $translatorOptions`;
- }
-
- file -f -op $fileOptions -typ $fileType -er $theFile;
-
- return true;
- }
-
- global proc referenceEdExportCB()
- //
- // Description:
- // Export everything currently selected as a reference.
- //
- {
- string $saveType = "mayaAscii";
- string $wsName = `workspace -q -fn`;
-
- if (`optionVar -exists defaultFileReferenceType`) {
- $saveType = `optionVar -q defaultFileReferenceType`;
- }
- setWorkingDirectory $wsName $saveType "scene";
-
- fileBrowser "referenceEdExportAsReference" "Export Reference" $saveType 101;
- }
-
- global proc referenceEdRemoveCB()
- //
- // Description:
- // Removed the file selected in the reference editor.
- //
- {
- global string $_selectedFile[];
- if (size($_selectedFile) == 1 && size($_selectedFile[0]) > 0) {
- string $result = `confirmDialog -t "Remove Reference"
- -m ("Removing the Reference to "
- +$_selectedFile[0]+" is Not Undoable.")
- -b "Remove" -b "Cancel" -db "Cancel"`;
- if ($result == "Remove") {
- file -rr $_selectedFile[0];
- $_selectedFile[0] = "";
- }
- }
- }
-
- global proc referenceEdSelectCB()
- //
- // Description:
- // A callback to select all of the contents of the file selected
- // in the reference editor.
- //
- {
- global string $_selectedFile[];
- if (size($_selectedFile) == 1 && size($_selectedFile[0]) > 0) {
- file -sa $_selectedFile[0];
- }
- }
-
- global proc referenceEdUnloadCB()
- //
- // Description:
- // A callback to unload a reference.
- //
- {
- global string $_selectedFile[];
- global string $_selectedRef[];
- if (size($_selectedFile) == 1 && size($_selectedFile[0]) > 0) {
- // Save the connections in the reference node.
- //
- file -ur $_selectedRef[0] $_selectedFile[0];
- }
- }
-
- global proc referenceEdLoadCB()
- //
- // Description:
- // A callback to load a reference.
- //
- {
- global string $_selectedFile[];
- if (size($_selectedFile) == 1 && size($_selectedFile[0]) > 0) {
- global string $_selectedRef[];
-
- file -lr $_selectedRef[0] $_selectedFile[0];
- }
- }
-
- global proc referenceEdSelectedUpdateList()
- //
- // Description:
- // Updates the reference list based on the selected.
- //
- {
- global string $_selectedFile[];
- global string $_selectedRef[];
-
- if (size($_selectedFile) == 0 || size($_selectedRef) == 0) {
- return;
- }
-
- referenceEdUpdateList($_selectedFile[0], $_selectedRef[0]);
- } // referenceEdSelectedUpdateList
-
-
- global proc referenceEdUpdateList(string $addFile, string $refNode)
- //
- // Description:
- // Adds the file to the list replace list.
- //
- {
- // Set the length of the list to 5.
- //
- int $MAX_SIZE = 5;
- int $nFn = `getAttr -size ($refNode + ".fn")`;
- int $nItems = ($nFn >= $MAX_SIZE) ? $MAX_SIZE : $nFn;
-
- // Two cases:
- // 1: The file was never used before, then pop this
- // to the top of the list and shove everything
- // else down.
- // 2: The file was used before, then put the file at the
- // top and push everything down to the file's old
- // level.
- //
- int $usedBefore = false;
- int $usedItem = 0;
- for ($i = 0; $i < $nItems; $i++) {
- string $fileName = `getAttr ($refNode+".fn["+$i+"]")`;
- if ($fileName == $addFile) {
- $usedBefore = true;
- $usedItem = $i;
- break;
- }
- }
-
- if (!$usedBefore) {
- if ($nItems < $MAX_SIZE) {
- $nItems++;
- }
- }
-
- string $newStr = $addFile;
- string $swap;
- for ($i = 0; $i < $nItems; $i++) {
- $swap = `getAttr ($refNode + ".fn["+$i+"]")`;
- setAttr -type "string" ($refNode+".fn["+$i+"]") $newStr;
- $newStr = $swap;
-
- if ($usedBefore && $usedItem == $i) {
- break;
- }
- }
- } // referenceEdUpdateList
-
- global proc referenceEdReplaceCB()
- //
- // Description:
- // A callback to replace the currently loaded reference file with
- // a new reference file, while still keeping the same reference node.
- //
- {
- global string $_selectedFile[];
-
- if (size($_selectedFile) == 1 && size($_selectedFile[0]) > 0) {
- global string $_selectedRef[];
- global string $gReplaceReferenceNode;
-
- $gReplaceReferenceNode = $_selectedRef[0];
-
- string $replacedFile = $_selectedFile[0];
- if (size($_selectedRef[0]) == 0) {
- // If a reference node does not exist, create a new one.
- //
- if (catch(`file -rfn $_selectedRef[0] $_selectedFile[0]`)) {
- // If adding the reference node failed, then the replace
- // will also fail.
- //
- return;
- }
-
- $gReplaceReferenceNode = `file -q -rfn $_selectedFile[0]`;
- }
-
- // Add the file to the list of replace files. Set the list
- // length to 5.
- //
- string $refNode = $gReplaceReferenceNode;
- referenceEdSelectedUpdateList();
-
- projectViewer ReplaceReference;
- }
- }
-
- global proc buildReferenceEdRecentMenu(string $parentMenu)
- //
- // Description:
- // Builds the recently selected files for a specific reference. If one
- // of the items is selected, the reference is replaced with that file.
- // The new file should move to the head of the list.
- {
- global string $_selectedFile[];
- global string $_selectedRef[];
-
- string $menu = ($parentMenu + "|referenceEdRecentFilesItem");
- if (size($_selectedRef) == 0) {
- menu -e -deleteAllItems $menu;
- return;
- }
-
- // Get the number of files previously used.
- //
- int $nListFiles = `getAttr -size ($_selectedRef[0]+".fn")`;
-
- // Get the list of files.
- //
- int $i, $j;
- string $fileList[];
- for ($i = 0, $j = 0; $i < $nListFiles; $i++) {
- string $nextFile = `getAttr ($_selectedRef[0]+".fn["+$i+"]")`;
- if (size($nextFile) == 0) {
- continue;
- }
- $fileList[$j++] = $nextFile;
- }
-
- // Pack the list, if necessary.
- //
- int $nFiles = `size($fileList)`;
- if ($i != $j) {
- for ($i = 0; $i < $nListFiles; $i++) {
- string $fileName;
- if ($i < $nFiles) {
- $fileName = $fileList[$i];
- }
- setAttr -type "string" ($_selectedRef[0]+".fn["+$i+"]") $fileName;
- }
- }
-
- string $oldParent = `setParent -q -menu`;
- setParent -menu $parentMenu;
-
- // Check and see if the current menu contains the same names as
- // the list in the reference node.
- //
- string $localList[] = `menu -q -itemArray $menu`;
- int $nLocalItems = `size($localList)`;
- if ($nFiles == $nLocalItems) {
- int $i;
- for ($i = 0; $i < $nLocalItems; $i++) {
- if ($localList[$i] != $fileList[$i]) {
- break;
- }
- }
- if ($i == $nLocalItems) {
- return;
- }
- }
-
- menu -e -deleteAllItems $menu;
- setParent -menu $menu;
-
- for ($i = 0; $i < $nFiles; $i++) {
- string $cmd = ("referenceEdSelectedUpdateList();" +
- "file -lr \"" + $_selectedRef[0] +
- "\" \"" + $fileList[$i] + "\";");
- menuItem -l $fileList[$i] -c $cmd;
- }
-
- setParent -menu $oldParent;
- }
-